/*
 * userAisle.h
 *
 *  Created on: Jun 16, 2011
 *      Author: peckb1
 */

#ifndef USERAISLE_H_
#define USERAISLE_H_

#include "userSharedDefinitions.h"
#include "usercommon.h"

typedef struct Aisle {
    int _aisleId;
    int _itemIds[MAX_ITEMS_PER_AISLE]; /* Array of item ids in the aisle */
    int _itemQty[MAX_ITEMS_PER_AISLE]; /* Array of qty for each item */
} Aisle;

int i;
int index;

/* Returns the Aisle Id */
int getAisleId(Aisle* aisle) {
    return (aisle->_aisleId);
}

/* Sets the aisle up with and item Id Array */
void set(Aisle* aisle, int aisleId, int itemIds[]) {
    aisle->_aisleId = aisleId;
    for(i = 0; i < MAX_ITEMS_PER_AISLE; i++){
      aisle->_itemIds[i] = itemIds[i];
      aisle->_itemQty[i] = INITIAL_AISLE_ITEM_COUNT;
    }
}

/* Used to find the array index on the shelf */
int findIndex(Aisle* aisle, int itemId) {

}

/* Adds one item to the aisle */
int restockItem(Aisle* aisle, int itemId) {
    index = findIndex(aisle, itemId);
    /* If index was found and Qty lower than 3, incriment qty */
    if(index>=0 && aisle->_itemQty[index] < 3) {
       aisle->_itemQty[index] = aisle->_itemQty[index] + 1;
       return TRUE;
    } else {
      return FALSE;
    }
}

/* Customer picks up one item from the aisle */
int pickUpItem(Aisle* aisle, int itemId) {
    index = findIndex(aisle, itemId);
    /* If index found, and there is at least one item, decriment qty */
    if(index>=0 && aisle->_itemQty[index] > 0){
        aisle->_itemQty[index] = aisle->_itemQty[index] - 1;
        return TRUE;
    } else {
        return FALSE;
    }
}

/* Prints out the aisle stats */
void printStats(Aisle* aisle) {
    printf_3("AisleId:", getAisleId(aisle), "\n");

    for(i=0; i<MAX_ITEMS_PER_AISLE; i++){
        printf_5("\tItemId:", aisle->_itemIds[i], " Qty:", aisle->_itemQty[i], "\n");
    }
}


#endif /* USERAISLE_H_ */
